<template>
  <el-table v-loading="loading" border :data="tableData" show-overflow-tooltip>
    <el-table-column label="设备名称" align="center" prop="inventoryCode" />
    <el-table-column label="告警内容" align="center" prop="inventoryName" />
    <el-table-column label="今日告警次数" align="center" prop="status" />
    <el-table-column
      label="告警开始时间"
      align="center"
      prop="storehouseName"
    />
    <el-table-column label="工段" align="center" prop="workSectionName" />
    <el-table-column label="产线" align="center" prop="pdcLineName" />
    <el-table-column label="工艺段" align="center" prop="processSectionName" />
    <el-table-column
      label="操作"
      align="center"
      fix="right"
      width="180"
      class-name="small-padding fixed-width"
    >
      <template #default="scope">
        <el-button
          v-if="scope.row.status === 'SUBMIT_TEMPORARY_STORAGE'"
          link
          type="primary"
          icon="edit"
          @click="handleUpdate(scope.row)"
          v-hasPermi="['system:inventory:edit']"
          >执行</el-button
        >
        <el-button
          v-if="scope.row.status === 'SUBMIT_TEMPORARY_STORAGE'"
          link
          type="primary"
          icon="edit"
          @click="handleUpdate(scope.row)"
          v-hasPermi="['system:inventory:edit']"
          >转办</el-button
        >
        <el-button
          v-if="scope.row.status === 'SUBMIT_TEMPORARY_STORAGE'"
          link
          type="primary"
          icon="delete"
          @click="handleClose(scope.row)"
          v-hasPermi="['system:inventory:remove']"
          >关闭</el-button
        >
      </template>
    </el-table-column>
  </el-table>

  <pagination
    v-show="total > 0"
    :total="total"
    v-model:page="queryParams.pageNum"
    v-model:limit="queryParams.pageSize"
    @pagination="getList"
  />
</template>

<script setup name="AlarmTable">
import { toRefs } from "vue";

const props = defineProps({
  api: {
    type: Function,
    default: null,
  },
  initParams: {
    type: Object,
    default: {},
  },
});
const loading = ref(true);
const tableData = ref([]);
const total = ref(0);
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    factoryCode: undefined,
    workshopCode: undefined,
    lineCode: undefined,
    sectionCode: undefined,
    storehouseCode: undefined,
    storehouseName: undefined,
    leaderName: undefined,
    status: undefined,
  },
});
const { queryParams, form } = toRefs(data);

/** 查询字典类型列表 */
function getList() {
  loading.value = true;
  if (props.api) {
    props
      .api({
        ...queryParams.value,
        ...props.initParams,
      })
      .then((response) => {
        tableData.value = response.rows;
        total.value = response.total;
        loading.value = false;
      });
  } else {
    loading.value = false;
    tableData.value = [];
    total.value = 0;
  }
}
function handleUpdate() {}
function handleClose() {}
getList();
</script>

<style lang="scss" scoped></style>
